//
//  NYAirlineViewController.m
//  NiuWaJiaoYu
//
//  Created by MinLison on 2018/1/6.
//  Copyright © 2018年 niuwaketang. All rights reserved.
//

#import "NYAirlineViewController.h"

//views
#import "NYAirlineProblemCell.h"
#import "NYRefreshFooter.h"

// request
#import "NYAirlineProblemRequest.h"

//models
#import "NYAirlineDataModel.h"


@interface NYAirlineViewController () <QMUITableViewDelegate>

@property (nonatomic, strong) NYAirlineProblemRequest *problemRequest;
@end

@implementation NYAirlineViewController

#pragma mark - Life Cycle Methods

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self initUI];
}
#pragma mark - Intial Methods
- (void)initUI {
    
    [self loadData];
}
- (void)initTableView {
    [super initTableView];
//    [self.tableView registerClass:[NYAirlineProblemCell class] forCellReuseIdentifier:[NYAirlineProblemCell className]];
}
- (void)configNimbus {
    [super configNimbus];
    self.tableViewModel.delegate = self;
}

- (void)loadData {
    
    [self setLoading:YES animation:YES];
    [self configNimbus];
    [self.problemRequest clearCache];
    self.problemRequest = [NYAirlineProblemRequest requestWithParams:@{kRequestKeyChannel:@(NYUserManager.channelID), kRequestKeyLoginCode : NOT_NULL_STRING_DEFAULT_EMPTY(NYUserManager.logincode), kRequestKeyUser_ID:NOT_NULL_STRING_DEFAULT_EMPTY(NYUserManager.user_id)}];

    @weakify(self);
    [[self.problemRequest pullDown] startWithSuccess:^(__kindof BaseRequest * _Nonnull request, __kindof NYAirlineDataModel * _Nonnull data) {
        
        @strongify(self);
        [self.tableViewModel removeAll];
        
        [self.tableViewModel addObjectsFromArray:data.list];
        [self.tableView reloadData];
        [self setSuccess];
    } failed:^(__kindof BaseRequest * _Nonnull request, NSError * _Nonnull error) {
        [self setError:error];
    }];
}
- (void)setSuccess {
    [super setSuccess];
    [self configRefreshFooter];
}
- (void)configRefreshFooter {
    
    @weakify(self);
    self.tableView.mj_footer = [NYRefreshFooter footerWithRefreshingBlock:^{
        @strongify(self);
        [[self.problemRequest pullUp] startWithSuccess:^(__kindof BaseRequest * _Nonnull request, __kindof NYAirlineDataModel * _Nonnull data) {
            
            [self.tableViewModel addObjectsFromArray:data.list];
            [self.tableView reloadData];
            [data.list count] == 0 ? [self.tableView.mj_footer endRefreshingWithNoMoreData] : [self.tableView.mj_footer endRefreshing];
        } failed:^(__kindof BaseRequest * _Nonnull request, NSError * _Nonnull error) {
            
            [self.tableView.mj_footer endRefreshingWithNoMoreData];
        }];
    }];
}

#pragma mark - Network Methods

#pragma mark - Target Methods

#pragma mark - Public Methods

#pragma mark - Private Method
- (void)configNavigationBar:(BaseNavigationBar *)navigationBar {
        [super configNavigationBar:navigationBar];
        self.title = @"在线答疑";
}
+ (NYViewControllerNavigationBarType)navigationBarType {
        
        return NYViewControllerNavigationBarTypeBlue;
}
- (BOOL)showChoseChannelIDRightView {
    return false;
}
#pragma mark - External Delegate

#pragma mark - UITableViewDelegate,UITableViewDataSource

#pragma mark - Setter Getter Methods

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
